<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="4" :lg="6" :md="8" :sm="24">
            <a-form-item label="图书名称" :wrapperCol="wrapperCol" :labelCol="labelCol">
              <a-input v-model="queryParam.name" placeholder="" />
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="6" :md="8" :sm="24">
            <a-form-item label="图书类型" :wrapperCol="wrapperCol" :labelCol="labelCol">
              <a-input v-model="queryParam.type" placeholder="" />
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="6" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">搜索</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <!-- <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button> -->
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('base_score')">导出</a-button> -->
      <!-- 高级查询区域 -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">还书</a>

          <a-divider type="vertical" />
           <a @click="handleDetail(record)">详情</a>
          <!-- <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown> -->
        </span>
      </a-table>
    </div>

    <base-score-modal ref="modalForm" @ok="modalFormOk"></base-score-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import BaseScoreModal from './modules/BaseScoreModal'
import JSuperQuery from '@/components/jeecg/JSuperQuery.vue'

export default {
  name: 'BaseScoreList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    BaseScoreModal,
    JSuperQuery,
  },
  data() {
    return {
      description: 'base_score管理页面',
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        // {
        //   title: '图书Id',
        //   align: 'center',
        //   dataIndex: 'bookId',
        // },
        {
          title: '图书名称',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '图书类型',
          align: 'center',
          dataIndex: 'type',
        },
        {
          title: '作者',
          align: 'center',
          dataIndex: 'author',
        },
        {
          title: '简介',
          align: 'center',
          dataIndex: 'intro',
          width:400
        },
        {
          title: '借书时间',
          align: 'center',
          dataIndex: 'borrowTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '还书时间',
          align: 'center',
          dataIndex: 'returnTime',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '积分',
          align: 'center',
          dataIndex: 'score',
        },
        {
          title: '读书笔记',
          align: 'center',
          dataIndex: 'note',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/base/baseScore/listInfo',
        delete: '/base/baseScore/delete',
        deleteBatch: '/base/baseScore/deleteBatch',
        exportXlsUrl: '/base/baseScore/exportXls',
        importExcelUrl: 'base/baseScore/importExcel',
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
     handleEdit: function (record) {
      this.$refs.modalForm.edit(record);
      this.$refs.modalForm.title = "还书";
      this.$refs.modalForm.disableSubmit = false;
    },
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'bookId', text: 'bookId' })
      fieldList.push({ type: 'string', value: 'userId', text: 'userId' })
      fieldList.push({ type: 'date', value: 'borrowTime', text: '借书时间' })
      fieldList.push({ type: 'date', value: 'returnTime', text: '还书时间' })
      fieldList.push({ type: 'number', value: 'score', text: '积分' })
      fieldList.push({ type: 'string', value: 'note', text: '读书笔记' })
      this.superFieldList = fieldList
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>